//
//  OrientationManager.m
//  McRemote
//
//  Created by Magic on 2/9/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "OrientationManager.h"

static OrientationManager *_orientationManager;

@implementation OrientationManager {
    BOOL isShowingLandscapeView;
}

@synthesize tabBarController;

- (void)awakeFromNib
{
    _orientationManager = self;
    
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateOrientation:) name:UIDeviceOrientationDidChangeNotification object:nil];
}

- (void)updateOrientation:(NSNotification *)notification
{
    [self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
    
}

- (void)updateLandscapeView
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (deviceOrientation == UIDeviceOrientationLandscapeLeft && !isShowingLandscapeView)
	{
        [self.tabBarController performSegueWithIdentifier:@"Trackpad" sender:nil];
        isShowingLandscapeView = YES;
    }
    else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
	{
        [self.tabBarController dismissModalViewControllerAnimated:YES];
        isShowingLandscapeView = NO;
    }
}

@end
